package com.pbs.utils;

import java.util.Calendar;
import java.util.UnknownFormatFlagsException;

public class Date {
	public static String getDate(DateFormat format, String separater) {
		if (separater == null) {
			throw new UnknownFormatFlagsException("unsupported for separater '" + separater + "'");
		}
		Calendar c = Calendar.getInstance();
		int mYear;
		int mMonth;
		int mDay;

		mYear = c.get(Calendar.YEAR);
		mMonth = c.get(Calendar.MONTH) + 1;// Months from the calendar are
		// offset by one. Add one if you
		// want human readable.
		mDay = c.get(Calendar.DAY_OF_MONTH);

		if (format == DateFormat.DDMMYYYY) {
			return mDay + separater + mMonth + separater + mYear;
		} else if (format == DateFormat.MMDDYYYY) {
			return mMonth + separater + mDay + separater + mYear;
		} else if (format == DateFormat.YYYYMMDD) {
			return mYear + separater + mMonth + separater + mDay;
		} else {
			return mDay + separater + mMonth + separater + mYear;
		}
	}
	
	public static String getTime() {
		Calendar c = Calendar.getInstance();

		int h;
		int m;
		int s;

		h = c.get(Calendar.HOUR_OF_DAY);
		m = c.get(Calendar.MINUTE);
		s = c.get(Calendar.SECOND);
		return h + ":" + m + ":" + s;
	}
	
	public static String getTime(String separater) {
		if (separater == null) {
			throw new UnknownFormatFlagsException("unsupported for separater '" + separater + "'");
		}
		Calendar c = Calendar.getInstance();

		int h;
		int m;
		int s;

		h = c.get(Calendar.HOUR_OF_DAY);
		m = c.get(Calendar.MINUTE);
		s = c.get(Calendar.SECOND);
		return h + separater + m + separater + s;
	}
}
